package com.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(4)
@Slf4j
@Aspect
//@Component
public class AspectDemo1 {

    @Pointcut("execution(* com.example.aop.controller.*.*(..))")
    public void pt(){}

    @Before("pt()")
    public void doBefore(){
        log.info("do before...");
    }

    @Around("pt()")
    public Object doAround(ProceedingJoinPoint joinPoint){
        log.info("do around before...");
        Object object;
        try {
           object  = joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }

        log.info("do around after");
        return object;
    }

    @After("pt()")
    public void doAfter(){
        log.info("do after...");
    }

    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("do after returning...");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing(){
        log.info("do after throwing...");
    }
}
